Skip to content

Fix dart tests#1248

Open
Fellmonkey wants to merge 5 commits intoappwrite:masterfrom
Fellmonkey:fix-dart-tests
Open

Fix dart tests#1248
Fellmonkey wants to merge 5 commits intoappwrite:masterfrom
Fellmonkey:fix-dart-tests

Conversation

@Fellmonkey
Copy link
Contributor

@Fellmonkey Fellmonkey commented Nov 4, 2025

Updates Dart test template to use the first enum value for string properties with enums when generating test data, instead of always using the example value. This ensures generated test data is valid for properties with restricted enum values.

What does this PR do?

This PR updates the Dart SDK test generation template (service_test.dart.twig) to properly handle enum properties in generated test mocks. Previously, all string properties used property.example as mock values, which could lead to invalid enum values causing "Bad state: No element" errors in model constructors like Message.fromMap when the example value didn't match any enum option.

The change adds conditional logic for string properties:

  • If the property has an enum defined, use the first enum value (property.enum[0]) as the mock value
  • Otherwise, fall back to using property.example as before

This ensures that generated tests use valid enum values for properties with enums, preventing runtime errors during test execution.

Test Plan

regenerate sdk and run dart test

also push changes and ensure the GitHub Actions workflow for Dart SDK completes successfully with all tests passing. #1247

before:
image
image
after:
{7AD8E36C-F2DB-45FC-887E-CD8B0C5C9ECA}

Have you read the Contributing Guidelines on issues?

Yes

Summary by CodeRabbit

  • New Features

    • Test data generation now prefers the first enum value for string properties when available, falling back to examples otherwise.
  • Tests

    • Response assertions adjusted: multi-model responses are validated as maps; single-model responses still expect specific types.
    • Account channel test now asserts a specific channel string rather than a wildcard.
  • Chores

    • No public API changes.

✏️ Tip: You can customize this high-level summary in your review settings.

Updates Dart test template to use the first enum value for string properties with enums when generating test data, instead of always using the example value. This ensures generated test data is valid for properties with restricted enum values.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 4, 2025

Walkthrough

Updates two test templates. In the Dart service test template, generated response-model test data for string properties now prefers the first enum value when an enum is present, falling back to the example otherwise; the response data map generation is updated accordingly. Test assertions for responses now check for a Map<String, dynamic> when a method defines multiple response models, otherwise they expect the specific model type. In the Flutter channel test template, the default account channel expectation changed from "account.*" to "account". No public APIs were changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The PR title 'Fix dart tests' is vague and doesn't clearly specify which tests are being fixed or what the underlying issue is. While it relates to the changes (Dart test templates), it lacks specificity about the actual problem (enum value selection) or the scope of changes. Use a more specific title that describes the main fix, such as 'Use enum values for string properties in Dart test generation' or 'Fix enum value selection in Dart service test template'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Fellmonkey
Copy link
Contributor Author

{F22D911D-7C4F-4580-992B-260C53E694C2}

Updated the Dart service test template to check for Map<String, dynamic> when multiple response models are present, improving test accuracy for methods with multiple possible response types.
@Fellmonkey
Copy link
Contributor Author

commit -> failed test
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant